﻿using EnvDTE;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using System;
using System.IO;
using System.Threading.Tasks;

namespace MyExtendProject.Common
{
    public class CommonCommandFunction
    {
        public static Solution GetActiveSolution()
        {
            DTE dte = Package.GetGlobalService(typeof(SDTE)) as DTE;
            return dte.Solution;
        }

        public static string GetSolutionPath()
        {
            return Path.GetDirectoryName(GetActiveSolution().FullName);
        }

        public static async Task<IVsOutputWindowPane> CreatePane(AsyncPackage package, Guid paneGuid, string title, bool visible, bool clearWithSolution)
        {
            IVsOutputWindow output = (IVsOutputWindow)(await package.GetServiceAsync(typeof(SVsOutputWindow)));

            // Create a new pane.  
            output.CreatePane(
                ref paneGuid,
                title,
                Convert.ToInt32(visible),
                Convert.ToInt32(clearWithSolution));

            // Retrieve the new pane.  
            output.GetPane(ref paneGuid, out IVsOutputWindowPane pane);

            return pane;
        }
    }
}
